<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加商家</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
		<style>
			.yanshi {
				height: 38px;
			    line-height: 1.3;
			    line-height: 38px\9;
			    border: 1px solid #e6e6e6;
			    background-color: #fff;
			    border-radius: 2px;
			    width: 211px;
			}
		</style>
	</head>

	<body>
		<form id="my_form" class="layui-form update_form" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">商铺名称</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="agent_name" lay-verify="required" placeholder="商铺名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item update_scbtn">
				<label class="layui-form-label">上传logo</label>
				<div class="layui-upload">
					<button type="button" class="layui-btn" id="test1">上传logo</button>
					<div class="layui-upload-list" style="    margin-left: 10%;">
						<img class="layui-upload-img" id="demo1" style="width: 200px;height: 200px;margin-left:100px;">
						<p id="demoText"></p>
					</div>
				</div>
				<input type="hidden" name='thumb' id='thumb' />
			</div>
			<div class="layui-form-item">				
				<label class="layui-form-label">行业分类</label>
				<div  class="layui-input-block"  style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="trade_type" onchange="select_trade(this);" lay-ignore class="yanshi" lay-filter="sel_1" lay-verify="required">
						{volist name="typelist" id="vo"}
						<option value="{$vo.id}">{$vo.type_name}</option>
						{/volist}
					</select>
				</div>				
			</div>
			<div class="layui-form-item">
			
				<label class="layui-form-label">行业二级分类</label>
				<div class="layui-input-block"  style="float: left; margin-right: 20px; margin-left: 0;" >
					<select id="trade_type2" name="trade_type2" lay-ignore class="yanshi" lay-filter="sel_1"  lay-verify="required">
			        	<option value="0">选择行业</option>
					</select>
				</div>			
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">联系人</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="user_name" lay-verify="required" placeholder="联系人" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">联系电话</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="mobile" lay-verify="required" placeholder="联系电话" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">店铺性质</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="store_property" id='store_property' lay-verify="required" lay-filter="sel_1">
						<option value=1>个人</option>
						<option value=2>企业</option>
						<option value=3>个体户</option>
					</select>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">会员手机号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="usermobile" lay-verify="required" placeholder="会员手机号" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">市场专员手机号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="scmobile" id="scmobile" placeholder="市场专员手机号" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<!--
            	作者：xx
            	时间：2018-05-28
            	描述：签约内容
            -->
            <div class="shxx_title">签约信息</div>
			<div class="layui-form-item">
				<label class="layui-form-label">商户号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="cb_login_name" lay-verify="required"  placeholder="商户号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">员工密钥</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="cb_clerk" lay-verify="required"  placeholder="员工密钥" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">银行费率</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="cb_huilu" lay-verify="required"  placeholder="银行费率" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<!--
            	作者：xx
            	时间：2018-05-28
            	描述：银行信息
            -->
    		<div class="shxx_title">资金结算账号(用于结算收款资金的银行帐号)</div>
            <div class="layui-form-item">
				<label class="layui-form-label">账户名</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="account_name" lay-verify="required"  placeholder="账户名" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">银行帐号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="bank_account" lay-verify="required" placeholder="银行帐号" autocomplete="off" class="layui-input">
					<p class="redtip">用于结算收款资金的银行账号。务必与账户名对应，否则将影响资金到账</p>
				</div>				
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">开户银行</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="open_bank" lay-verify="required"  placeholder="开户银行" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">支行名称</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="branch_name" lay-verify="required"  placeholder="支行名称" autocomplete="off" class="layui-input">
					<p class="redtip">支行名称为必填项</p>
				</div>			
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">支行所在地区</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="branch_address" lay-verify="required"  placeholder="支行所在地区" autocomplete="off" class="layui-input">
					<p class="redtip">支行所在地区为必填项</p>
				</div>				
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">预留手机号码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="yl_mobile" lay-verify="required"  placeholder="预留手机号码" autocomplete="off" class="layui-input">

				</div>			
			</div>	
			<div class="layui-form-item update_btnbox" style="text-align: center;margin-left:unset">
				<div class="layui-input-block" style="    max-width: unset;float: unset;">
					<button type="button" lay-submit class="layui-btn" lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>

</html>
<script type="text/javascript" src="__PUBLIC__/static/release/wangEditor.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/js/assist.js"></script>
<script>
	function add_agent() {
		var scmobile = $('#scmobile').val();
		var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //验证规则
		if(!reg.test(scmobile)) {
			layer.msg('市场专员手机号码格式不正确'); 
			return;
		}
		$.ajax({
			type: "post",
			url: "{:url('oem/accounts/add_agent')}",
			data: $('#my_form').serialize(), //表单数据
			success: function(data) {
				if(data.code == 200) {
					layer.msg('添加成功', {
						icon: 1,
						time: 1500 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						window.parent.location.reload();
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
						parent.layer.close(index);
					});
				} else {
					layer.msg(data.msg); //保存成功提示
				}
			},
			error: function(data) {
				var a = data;
			}
		});

	}
	//图片上传
	layui.use(['form', 'upload'], function() {
		var $ = layui.jquery,
			upload = layui.upload,
			form = layui.form;

		//普通图片上传
		var uploadInst = upload.render({
			elem: '#test1',
			auto: false //选择文件后不自动上传
				,
			choose: function(obj) {
				//将每次选择的文件追加到文件队列
				var files = obj.pushFile();

				//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
				obj.preview(function(index, file, result) {
					$('#demo1').attr('src', result); //图片链接（base64）
					var sendData = result.substring(result.indexOf(";base64,") + 8);
					$.post("{:url('oem/accounts/upload')}", {
						value: sendData
					}, function(data) {
						if(data.code == '200') {
							$('#thumb').val(data.url);
						} else {
							console.log(data);
						}
					});
				});
			},
			url: "{:url('oem/accounts/upload')}",
			accept: 'images'
		});
		//监听提交
		form.on('submit(demo1)', function(data) {
			add_agent();
			return false;
		});
	})
	
	function select_trade(obj){
		var trade_id=$(obj).val();
		var lay = layer.load(0, {shade: false,time: 1.5 * 1000});
		$.ajax({
				type: 'post',
				url: "{:url('index/get_trades')}",
				data: {
					trade_id:trade_id
				},
				success: function(data) {
					var list=data.data;
					if(list){
						var html="<option value='0'>选择行业</option>";
						for(var i=0;i<list.length;i++){
							var trade=list[i];
							html+="<option value="+trade['id']+">"+trade['type_name']+"</option>";
						}
						$("#trade_type2").html(html);

					}
				}
		})
		
	}

</script>